#include "Cube.h"

Cube::Cube(float l) :
    l(l)
{
//    Inicializa os vértices do cubo centrado na origem do sistema local

    float d = l/2.0;

    vertices[0] = Point3f(-d, -d, d);
    vertices[1] = Point3f(d, -d, d);
    vertices[2] = Point3f(d, -d, -d);
    vertices[3] = Point3f(-d, -d, -d);

    vertices[4] = Point3f(-d, d, d);
    vertices[5] = Point3f(d, d, d);
    vertices[6] = Point3f(d, d, -d);
    vertices[7] = Point3f(-d, d, -d);
}

void Cube::draw()
{
    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_QUADS);
        glNormal3f(0.0, -1.0, 0.0);
        glVertex3fv(&vertices[0].x);
        glVertex3fv(&vertices[3].x);
        glVertex3fv(&vertices[2].x);
        glVertex3fv(&vertices[1].x);

        glNormal3f(1.0, 0.0, 0.0);
        glVertex3fv(&vertices[1].x);
        glVertex3fv(&vertices[2].x);
        glVertex3fv(&vertices[6].x);
        glVertex3fv(&vertices[5].x);

        glNormal3f(0.0, 1.0, 0.0);
        glVertex3fv(&vertices[4].x);
        glVertex3fv(&vertices[5].x);
        glVertex3fv(&vertices[6].x);
        glVertex3fv(&vertices[7].x);

        glNormal3f(-1.0, 0.0, 0.0);
        glVertex3fv(&vertices[3].x);
        glVertex3fv(&vertices[0].x);
        glVertex3fv(&vertices[4].x);
        glVertex3fv(&vertices[7].x);

        glNormal3f(0.0, 0.0, 1.0);
        glVertex3fv(&vertices[0].x);
        glVertex3fv(&vertices[1].x);
        glVertex3fv(&vertices[5].x);
        glVertex3fv(&vertices[4].x);

        glNormal3f(0.0, 0.0, -1.0);
        glVertex3fv(&vertices[2].x);
        glVertex3fv(&vertices[3].x);
        glVertex3fv(&vertices[7].x);
        glVertex3fv(&vertices[6].x);
    glEnd();
}
